﻿<%@ Page Title="" Language="C#" MasterPageFile="ReconSite.Master" AutoEventWireup="true" CodeBehind="DiscountPenaltyMaintenance.aspx.cs" Inherits="Recon.Portal.WebUI.DiscountPenaltyMaintenance" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleHolder" runat="server">
    <title>Discount/Penalty Master</title>
</asp:Content>
<asp:Content ID="BodyContent" ContentPlaceHolderID="BodyHolder" runat="server">
    <div class="formDiv" style="width: 72%">
        <h2 class="formTitle">Discount/Penalty Master</h2>
        <h1 class="formError" style="text-align: right; font-size: smaller; color: #CC2900;">Fields marked with * are mandatory</h1>
        <%--<asp:Panel ID="pnlStatement" runat="server" Visible ="false">--%>
        <table cellspacing="1" cellpadding="1" border="0" width="100%">
            <tr>
                <td align="right">Discount/Penalty
                </td>
                <td>
                    <asp:RadioButtonList ID="rbOption" runat="server" RepeatDirection="Horizontal"
                        RepeatLayout="Flow" AutoPostBack="True" OnSelectedIndexChanged="rbOption_SelectedIndexChanged">
                        <asp:ListItem Value="D" Selected="True">Discount</asp:ListItem>
                        <asp:ListItem Value="P">Penalty</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
            </tr>
            <%-- <tr>
                <td align="right" style="width: 18%">Customer ID<span class="required">*</span>
                </td>
                <td colspan="3">
                    <asp:Label ID="lblCustmerName" runat="server" CssClass="lable" ForeColor="#ff8400"/>
                    <%--<asp:DropDownList ID="ddlCustomer" runat="server" Width="300">
                        <asp:ListItem Value="0">Please Select Customer</asp:ListItem>
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="reqCustomerId" runat="server"
                        ErrorMessage="Select Customer ID." CssClass="formError"
                        ControlToValidate="ddlCustomer" SetFocusOnError="True"></asp:RequiredFieldValidator>--%>
           <%-- </td>

            </tr>--%>               <%--<asp:Button ID="Button1" runat="server" Text="..." UseSubmitBehavior="False" CausesValidation="False"
                        OnClick="Button1_Click1" />--%>
            <tr>
                <td align="right" style="width: 18%; padding-bottom: 12px">Effective Date<span class="required">*</span>
                </td>

                <td>
                    <input id="txtEffectiveDt" size="20" style="width: 125px" type="text"
                        runat="server" enableviewstate="false" readonly="readonly" />
                    <%--<asp:Button ID="Button1" runat="server" Text="..." UseSubmitBehavior="False" CausesValidation="False"
                        OnClick="Button1_Click1" />--%>
                    <asp:RequiredFieldValidator ID="reqEffectiveDt"
                        runat="server" ErrorMessage="Effective Date is mandatory" CssClass="formError"
                        ControlToValidate="txtEffectiveDt" SetFocusOnError="True"></asp:RequiredFieldValidator>


                </td>
            </tr>
            <tr>
                <td align="right" style="width: 18%; padding-bottom: 12px">Code<span class="required">*</span>
                </td>

                <td colspan="3">
                    <asp:TextBox id="txtCode" MaxLength="10" style="width: 125px" 
                        runat="server" ></asp:TextBox>
                    <asp:RequiredFieldValidator ID="reqCode"
                        runat="server" ErrorMessage="Discount/Penalty Code is mandatory" CssClass="formError"
                        ControlToValidate="txtCode" SetFocusOnError="True"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="regCode" runat="server"
                    ErrorMessage="Enter Valid Code." CssClass="formError"
                    ControlToValidate="txtCode" SetFocusOnError="True"
                    ValidationExpression="^[a-zA-Z0-9]{1,10}$"></asp:RegularExpressionValidator>
                </td>
                </tr>
            <tr>
                <td align="right" style="width: 18%">Day Start
                </td>
                <td>

                    <asp:TextBox ID="txtDayStart" runat="server" MaxLength="4"></asp:TextBox>
                    <asp:RegularExpressionValidator ID="regDayStart" runat="server"
                        ErrorMessage="Enter valid value." CssClass="formError"
                        ControlToValidate="txtDayStart" SetFocusOnError="True"
                        ValidationExpression="^[0-9]{1,4}$"></asp:RegularExpressionValidator>
                </td>
                <td align="right">Day End
                </td>
                <td>
                    <asp:TextBox ID="txtDayEnd" runat="server" MaxLength="4"></asp:TextBox>
                    <asp:RegularExpressionValidator ID="regDayEnd" runat="server"
                        ErrorMessage="Enter valid value." CssClass="formError"
                        ControlToValidate="txtDayEnd" SetFocusOnError="True"
                        ValidationExpression="^[0-9]{1,4}$"></asp:RegularExpressionValidator>
                </td>
            </tr>


            <tr>
                <td align="right" style="width: 18%; padding-bottom: 12px">Discount/Penalty %<span class="required">*</span>
                </td>
                <td colspan="3">
                    <asp:TextBox ID="txtPercentage" runat="server" MaxLength="6"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="reqPercentage" runat="server"
                        ErrorMessage="Percentage is mandatory" CssClass="formError"
                        ControlToValidate="txtPercentage" SetFocusOnError="True"></asp:RequiredFieldValidator>
                    &nbsp;<asp:RegularExpressionValidator ID="regPercentage" runat="server"
                        ErrorMessage="Invalid Percentage" CssClass="formError"
                        ControlToValidate="txtPercentage" SetFocusOnError="True"
                        ValidationExpression="^[0-9.]{1,6}$"></asp:RegularExpressionValidator>
                </td>
            </tr>

            <tr>
                <td align="right" style="width: 18%; padding-bottom: 12px">Minimum Amount
                </td>
                <td>
                    <asp:TextBox ID="txtMinAmount" runat="server" MaxLength="13"></asp:TextBox>

                    <asp:RequiredFieldValidator ID="reqMinAmount" runat="server"
                        ErrorMessage="Minimum Amount is mandatory" CssClass="formError"
                        ControlToValidate="txtMinAmount" SetFocusOnError="True"></asp:RequiredFieldValidator>
                    &nbsp;<asp:RegularExpressionValidator ID="regMinAmount" runat="server"
                        ErrorMessage="Invalid Amount" CssClass="formError"
                        ControlToValidate="txtMinAmount" SetFocusOnError="True"
                        ValidationExpression="^[0-9.]{1,12}$"></asp:RegularExpressionValidator>

                </td>
                <td align="right" style="width: 18%; padding-bottom: 12px">Maximum Amount
                </td>
                <td>
                    <asp:TextBox ID="txtMaxAmount" runat="server" MaxLength="13"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="reqMaxAmount" runat="server"
                        ErrorMessage="Maximum Amount is mandatory" CssClass="formError"
                        ControlToValidate="txtMaxAmount" SetFocusOnError="True"></asp:RequiredFieldValidator>
                    &nbsp;<asp:RegularExpressionValidator ID="regMaxAmount" runat="server"
                        ErrorMessage="Invalid Amount" CssClass="formError"
                        ControlToValidate="txtMaxAmount" SetFocusOnError="True"
                        ValidationExpression="^[0-9.]{1,12}$"></asp:RegularExpressionValidator>

                </td>
            </tr>

            <tr>
                <td align="right">
                    <asp:HiddenField ID="HiddenField1" runat="server" />
                    &nbsp;
                </td>
                <td colspan="3">
                    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />&nbsp;
                <asp:Button ID="btnCancel" runat="server" Text="Reset" CausesValidation="False" OnClick="btnCancel_Click" />
                </td>
            </tr>
        </table>
          <div style="height:380px; width:900px; overflow:auto;">
              <asp:Panel ID ="pnlDisc" runat ="server" Visible="true">
                <asp:GridView ID="gvDisc" runat="server" AllowPaging="false" 
                        AutoGenerateColumns="False" Width="850"
                        HeaderStyle-BackColor="silver" HeaderStyle-ForeColor="#6f788f" 
                            HeaderStyle-Font-Bold="false" OnRowDataBound="gvDisc_RowDataBound"  >
                    <EmptyDataTemplate>
                        <asp:Label ID="lblNoRows" runat="server" Text="No records found for discounts." />
                    </EmptyDataTemplate>
                    <Columns>
                        
                         <asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:LinkButton  ID = "lnkSelect" runat="server"  Text = "Select" CausesValidation="false" CommandName="Select"></asp:LinkButton>
                            </ItemTemplate>
                          </asp:TemplateField>
                        <asp:TemplateField HeaderText="Discount Code" ShowHeader="False" ItemStyle-HorizontalAlign="Center">
                   <ItemTemplate>
                       <asp:Label ID="lbtnDisc_Code" runat="server"  Text='<%# Eval("discountPenalty") %>'></asp:Label>
                   </ItemTemplate>
               </asp:TemplateField>
            <asp:TemplateField HeaderText="Date" ItemStyle-HorizontalAlign="Center">                                   
                <ItemTemplate>
                    <asp:Label ID="lbleffectiveDate" runat="server" Text='<%# Eval("effectiveDate") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField> 
            <asp:TemplateField HeaderText="Days Start" ItemStyle-HorizontalAlign="Center">                                   
                <ItemTemplate>
                    <asp:Label ID="lblDays_Start" runat="server" Text='<%# Eval("daySatrt") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>  
            <asp:TemplateField HeaderText="Days End" ItemStyle-HorizontalAlign="Center">                                   
                <ItemTemplate>
                    <asp:Label ID="lblDays_End" runat="server" Text='<%# Eval("dayEnd") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>  
            <asp:TemplateField HeaderText="Percentage %" ItemStyle-HorizontalAlign="Center">                                   
                <ItemTemplate>
                    <asp:Label ID="lblDiscount_Percentage" runat="server" Text='<%# Eval("percentage") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>  
            <asp:TemplateField HeaderText="Min Amount" ItemStyle-HorizontalAlign="Center">                                   
                <ItemTemplate>
                    <asp:Label ID="lblMin_Amount" runat="server" Text='<%# Eval("minAmount") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField> 
            <asp:TemplateField HeaderText="Max Amount" ItemStyle-HorizontalAlign="Center">                                   
                <ItemTemplate>
                    <asp:Label ID="lblMax_Amount" runat="server" Text='<%# Eval("maxAmount") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>           
           
                        <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ItemStyle-HorizontalAlign="Center"/>
                         <asp:TemplateField HeaderText="Id"  >                                   
                <ItemTemplate>
                    <asp:Label ID="lblId" runat="server" Text='<%# Eval("autoIncrementId") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField> 
                    </Columns>
                </asp:GridView>
                </asp:Panel>
              <asp:Panel ID ="pnlPenalty" runat ="server" Visible="false">
              <asp:GridView ID="gvPenalty" runat="server"  
         AllowPaging="false" 
                        AutoGenerateColumns="False" Width="850"
                        HeaderStyle-BackColor="silver" HeaderStyle-ForeColor="#6f788f" 
                            HeaderStyle-Font-Bold="false"  OnRowDataBound="gvPenalty_RowDataBound">
            <EmptyDataTemplate>
                        <asp:Label ID="lblPenaltyNoRows" runat="server" Text="No records found for penalty." />
                    </EmptyDataTemplate>
                    <Columns>
                        
                         <asp:TemplateField HeaderText="" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:LinkButton  ID = "lnkSelectPenalty" runat="server"  Text = "Select" CausesValidation="false" CommandName="Select"></asp:LinkButton>
                            </ItemTemplate>
                          </asp:TemplateField>
                        <asp:TemplateField HeaderText="Penalty Code" ShowHeader="False" ItemStyle-HorizontalAlign="Center">
                   <ItemTemplate>
                       <asp:Label ID="lbtnPenalty_Code" runat="server"  Text='<%# Eval("discountPenalty") %>'></asp:Label>
                   </ItemTemplate>
               </asp:TemplateField>
            <asp:TemplateField HeaderText="Date" ItemStyle-HorizontalAlign="Center">                                   
                <ItemTemplate>
                    <asp:Label ID="lblPenaltyeffectiveDate" runat="server" Text='<%# Eval("effectiveDate") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField> 
            <asp:TemplateField HeaderText="Days Start" ItemStyle-HorizontalAlign="Center">                                   
                <ItemTemplate>
                    <asp:Label ID="lblPenaltyDays_Start" runat="server" Text='<%# Eval("daySatrt") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>  
            <asp:TemplateField HeaderText="Days End" ItemStyle-HorizontalAlign="Center">                                   
                <ItemTemplate>
                    <asp:Label ID="lblPenaltyDays_End" runat="server" Text='<%# Eval("dayEnd") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>  
            <asp:TemplateField HeaderText="Percentage %" ItemStyle-HorizontalAlign="Center">                                   
                <ItemTemplate>
                    <asp:Label ID="lblPenalty_Percentage" runat="server" Text='<%# Eval("percentage") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>  
            <asp:TemplateField HeaderText="Min Amount" ItemStyle-HorizontalAlign="Center">                                   
                <ItemTemplate>
                    <asp:Label ID="lblPenaltyMin_Amount" runat="server" Text='<%# Eval("minAmount") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField> 
            <asp:TemplateField HeaderText="Max Amount" ItemStyle-HorizontalAlign="Center">                                   
                <ItemTemplate>
                    <asp:Label ID="lblPenaltyMax_Amount" runat="server" Text='<%# Eval("maxAmount") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>           
           
                        <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ItemStyle-HorizontalAlign="Center"/>
                         <asp:TemplateField HeaderText="Id"  >                                   
                <ItemTemplate>
                    <asp:Label ID="lblPenaltyId" runat="server" Text='<%# Eval("autoIncrementId") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField> 
                    </Columns>
            <HeaderStyle BackColor="silver" Font-Bold="false" ForeColor="#6f788f"/>
        </asp:GridView>
                  </asp:Panel>
          </div>
        <asp:UpdatePanel ID="upUnmatchedLists" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <div id="pnlMatchList" runat="server" class="pnlMatchList">
                    <span style="azimuth: center;">
                        <div id="Div1" class="formDiv" runat="server">
                            <center>
                                <asp:Label ID="lblMessage" runat="server" CssClass="lable" />
                            </center>
                        </div>
                    </span>
                    <div class="formDiv" style="width: 30%;">
                        <center>
                            <asp:Button ID="btnok" runat="server" Text="OK" OnClick="btnok_Click" CausesValidation="False" />
                        </center>
                    </div>
                </div>
                <div style="display: none">
                    <asp:Button ID="btnManualPopup" runat="server" />
                </div>
                <ajax:ModalPopupExtender ID="btnClickPopup" runat="server" PopupControlID="pnlMatchList"
                    TargetControlID="btnManualPopup" BackgroundCssClass="modalBackground" RepositionMode="RepositionOnWindowScroll" OkControlID="btnok">
                </ajax:ModalPopupExtender>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>


     <script type="text/javascript">
         $(function () {
             $("[id$=txtEffectiveDt]").datepicker({
                 showOn: 'button',
                 buttonImageOnly: true,
                 buttonImage: '../Images/cal.gif',
                 dateFormat: 'dd-mm-yy'
             });
         });


         $(function () {
             $("[id*=lnkSelectPenalty]").click(function () {
                 var tr = $(this).closest('tr');
                 //alert($(this).closest('tr').find('span[id*="lnkSelect"]').attr('Text'));
                 var discCode1 = $(tr).find('span[id*="lbtnPenalty_Code"]').text();
                 var effective1 = $(tr).find('span[id*="lblPenaltyeffectiveDate"]').text();
                 var dStart1 = $(tr).find('span[id*="lblPenaltyDays_Start"]').text();
                 var dEnd1 = $(tr).find('span[id*="lblPenaltyDays_End"]').text();
                 var DiscPerc1 = $(tr).find('span[id*="lblPenalty_Percentage"]').text();
                 var minAmt1 = $(tr).find('span[id*="lblPenaltyMin_Amount"]').text();
                 var maxAmt1 = $(tr).find('span[id*="lblPenaltyMax_Amount"]').text();
                 var autoId1 = $(tr).find('span[id*="lblPenaltyId"]').text();

                 $("#<%= txtCode.ClientID %>").val(discCode1).text();
                 $("#<%= txtEffectiveDt.ClientID %>").val(effective1).text();
                 $("#<%= txtDayStart.ClientID %>").val(dStart1).text();
                 $("#<%= txtDayEnd.ClientID %>").val(dEnd1).text();
                 $("#<%= txtMinAmount.ClientID %>").val(minAmt1).text();
                 $("#<%= txtMaxAmount.ClientID %>").val(maxAmt1).text();
                 $("#<%= txtPercentage.ClientID %>").val(DiscPerc1).text();
                 $("#<%= HiddenField1.ClientID %>").val(autoId1).text();

                        var btntext = "Modify";
                        $("#<%= btnSubmit.ClientID %>").val(btntext).text();
                        return false;

                    });
         });

         $(function () {
             $("[id*=lnkSelect]").click(function () {
                 var tr = $(this).closest('tr');
                 //alert($(this).closest('tr').find('span[id*="lnkSelect"]').attr('Text'));
                 var discCode = $(tr).find('span[id*="lbtnDisc_Code"]').text();
                 var effective = $(tr).find('span[id*="lbleffectiveDate"]').text();
                 var dStart = $(tr).find('span[id*="lblDays_Start"]').text();
                 var dEnd = $(tr).find('span[id*="lblDays_End"]').text();
                 var DiscPerc = $(tr).find('span[id*="lblDiscount_Percentage"]').text();
                 var minAmt = $(tr).find('span[id*="lblMin_Amount"]').text();
                 var maxAmt = $(tr).find('span[id*="lblMax_Amount"]').text();
                 var autoId = $(tr).find('span[id*="lblId"]').text();

                 //$("[id*=lblId]").attr('visible', false);

                 $("#<%= txtCode.ClientID %>").val(discCode).text();
                 $("#<%= txtEffectiveDt.ClientID %>").val(effective).text();
                 $("#<%= txtDayStart.ClientID %>").val(dStart).text();
                 $("#<%= txtDayEnd.ClientID %>").val(dEnd).text();
                 $("#<%= txtMinAmount.ClientID %>").val(minAmt).text();
                 $("#<%= txtMaxAmount.ClientID %>").val(maxAmt).text();
                 $("#<%= txtPercentage.ClientID %>").val(DiscPerc).text();
                 $("#<%= HiddenField1.ClientID %>").val(autoId).text();

                 var btntext = "Modify";
                 $("#<%= btnSubmit.ClientID %>").val(btntext).text();

                        return false;

             });
          });
    </script>


</asp:Content>
